package tr.edu.ege.seagent.hobnobontology.instance;

import tr.edu.ege.seagent.hobnobontology.schema.HobNobVocabulary;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;

/**
 * This class creates new instance about our yanyanayizbiz RDF schema model.
 * 
 * @author etmen
 * 
 */

public class HobNobSampleModelCreator {

	/**
	 * Name of chios activity.
	 */
	public static final String CHIOS_ACTIVITY_NAME = "Sakız Adası Gezisi";

	/**
	 * x-Coordinate of the Chios Island.
	 */
	public static final double CHIOS_X_COORDINATE = 38.365079;

	/**
	 * y-Coordinate of the Chios Island.
	 */
	public static final double CHIOS_Y_COORDINATE = 26.136789;

	/**
	 * Notification message of the seagent notification event.
	 */
	public static final String MSG_SEAGENT_NOTIFICATION = "Seagentte birlikteler";

	/**
	 * x-Coordinate of the Seagent
	 */
	public static final double SEAGENT_X_COORDINATE = 38.458042;

	/**
	 * y-Coordinate of the Seagent
	 */
	public static final double SEAGENT_Y_COORDINATE = 27.213346;

	/**
	 * Notification message of the cafe pi notification event.
	 */
	public static final String MSG_CAFEPI_NOTIFICATION = "Cafe pi' de kokteyl yudumluyorlar";

	/**
	 * x-Coordinate of Cafe Pi
	 */
	public static final double CAFE_PI_X_COORDINATE = 38.432867;

	/**
	 * y-Coordinate of Cafe Pi
	 */
	public static final double CAFE_PI_Y_COORDINATE = 27.136788;

	/**
	 * Instance creator to construct the sample model.
	 */
	private HobNobInstanceCreator instanceCreator;

	private Model instanceModel;

	/**
	 * Creates a new instance of {@link HobNobSampleModelCreator}. This
	 * constructor initializes sample model and {@link HobNobInstanceCreator}.
	 */
	public HobNobSampleModelCreator() {
		this.instanceModel = ModelFactory.createDefaultModel();
		this.instanceCreator = new HobNobInstanceCreator(instanceModel);
	}

	/**
	 * Creates Chios-Activity
	 * 
	 * Creates the type of Activity Chios
	 * 
	 * Adds literals which regard to Activity of Chios
	 * 
	 * Creates resource statement between member (who joins to the activityF)
	 * and activity,
	 * 
	 * Creates resource statement between activity and location of activity
	 */
	public void createChiosActivity() {

		// Creates the type of Class of Chios Activity.
		instanceCreator.createInstance(
				HobNobInstanceVocabulary.ACTIVITY_CHIOS_URI,
				HobNobVocabulary.ACTIVITY_URI);

		// Creates the name of Chios Activity.
		instanceCreator.createLiteralStatement(
				HobNobInstanceVocabulary.ACTIVITY_CHIOS_URI,
				HobNobVocabulary.ACTIVITY_NAME, CHIOS_ACTIVITY_NAME);

		// Creates the resource statement of member-activity
		instanceCreator.createResourceStatement(
				HobNobInstanceVocabulary.MEMBER_BAHTI_URI,
				HobNobVocabulary.MEMBER_JOIN_ACTIVITY_URI,
				HobNobInstanceVocabulary.ACTIVITY_CHIOS_URI);

		// Creates the resource statement of member-activity
		instanceCreator.createResourceStatement(
				HobNobInstanceVocabulary.MEMBER_CEREN_URI,
				HobNobVocabulary.MEMBER_JOIN_ACTIVITY_URI,
				HobNobInstanceVocabulary.ACTIVITY_CHIOS_URI);

		// Creates the resource statement of activity-location
		instanceCreator.createResourceStatement(
				HobNobInstanceVocabulary.ACTIVITY_CHIOS_URI,
				HobNobVocabulary.ACTIVITY_AT_LOCATION_URI,
				HobNobInstanceVocabulary.LOCATION_CHIOS_URI);
	}

	/**
	 * Creates chios location statements.
	 */
	public void createChiosLocation() {
		// ChiosLocation is type of "Location"
		instanceCreator.createInstance(
				HobNobInstanceVocabulary.LOCATION_CHIOS_URI,
				HobNobVocabulary.LOCATION_URI);
		// x-Coordinate of ChiosLocation
		instanceCreator.createLiteralStatement(
				HobNobInstanceVocabulary.LOCATION_CHIOS_URI,
				HobNobVocabulary.X_COORDINATE, CHIOS_X_COORDINATE);
		// y-Coordinate of ChiosLocation
		instanceCreator.createLiteralStatement(
				HobNobInstanceVocabulary.LOCATION_CHIOS_URI,
				HobNobVocabulary.Y_COORDINATE, CHIOS_Y_COORDINATE);
		// Chios dbpedia resource
		instanceCreator.createResourceStatement(
				HobNobInstanceVocabulary.LOCATION_CHIOS_URI,
				HobNobVocabulary.LOCATION_HAS_DBPEDIA_URI,
				HobNobInstanceVocabulary.CHIOS_DBPEDIA_URI);
	}

	/**
	 * Creates Members with given name, surname, eMail, phoneNumber and gender
	 * 
	 * And creates friend relation about that members
	 * 
	 */
	public void createMembers() {
		// Creation of BAHTI
		instanceCreator.createMember(HobNobInstanceVocabulary.MEMBER_BAHTI_URI,
				HobNobInstanceVocabulary.BAHTI_NAME,
				HobNobInstanceVocabulary.BAHTI_SURNAME,
				HobNobInstanceVocabulary.BAHTI_EMAIL,
				HobNobInstanceVocabulary.BAHTI_PHONE,
				HobNobInstanceVocabulary.LANGUAGE_ENGLISH,
				HobNobVocabulary.MALE_URI);

		// Creation of TAYFUN
		instanceCreator.createMember(
				HobNobInstanceVocabulary.MEMBER_TAYFUN_URI,
				HobNobInstanceVocabulary.TAYFUN_NAME,
				HobNobInstanceVocabulary.TAYFUN_SURNAME,
				HobNobInstanceVocabulary.TAYFUN_EMAIL,
				HobNobInstanceVocabulary.TAYFUN_PHONE,
				HobNobInstanceVocabulary.LANGUAGE_ENGLISH,
				HobNobVocabulary.MALE_URI);

		// Creation of CEREN
		instanceCreator.createMember(HobNobInstanceVocabulary.MEMBER_CEREN_URI,
				HobNobInstanceVocabulary.CEREN_NAME,
				HobNobInstanceVocabulary.CEREN_SURNAME,
				HobNobInstanceVocabulary.CEREN_EMAIL,
				HobNobInstanceVocabulary.CEREN_PHONE,
				HobNobInstanceVocabulary.LANGUAGE_ENGLISH,
				HobNobVocabulary.FEMALE_URI);

		// Creation of Friend relations
		instanceCreator.createFriendOfMember(
				HobNobInstanceVocabulary.MEMBER_BAHTI_URI,
				HobNobVocabulary.FRIEND_URI,
				HobNobInstanceVocabulary.MEMBER_CEREN_URI);
		instanceCreator.createFriendOfMember(
				HobNobInstanceVocabulary.MEMBER_CEREN_URI,
				HobNobVocabulary.FRIEND_URI,
				HobNobInstanceVocabulary.MEMBER_BAHTI_URI);
	}

	/**
	 * Creates statements that which except for seagent statements.
	 * 
	 * @return instanceModel;
	 */
	public Model createModelExceptForSeagent() {

		// Members are being created
		createMembers();
		// Chios location are being created
		createChiosLocation();
		// Chios-activity is being created
		createChiosActivity();

		return instanceModel;

	}

	/**
	 * Creates new instance as for that given yanyayizbiz RDF schema.
	 * 
	 * @return created model.
	 */
	public Model createNewInstance() {
		// Seagent statements are being creating...
		createSeagentModel();
		// Statements that except for seagent are being creating...
		createModelExceptForSeagent();

		return instanceModel;

	}

	/**
	 * Creates new istance with istanbul notifcation statements as for that
	 * given yanyanayizbiz RDF schema.
	 * 
	 * @return created model.
	 */
	public Model createNewInstanceWithIstanbulandCafePiNotification() {
		// Seagent statements are being created...
		createSeagentModel();
		// Statements that except for seagent are being created...
		createModelExceptForSeagent();
		// Istanbul statements are being created...
		createInstanbulStatements();
		// Cafe pi statements are being created...
		createCafePiModel();

		return instanceModel;
	}
	
	/**
	 * Creates statements that which related with cafe pi notification.
	 * 
	 * @return instanceModel
	 */
	public void createCafePiModel() {
		// Cafe pi-notification is being created...
		createCafePiNotification();
		// Cafe pi-location is being created...
		createCafePiLocation();
		
	}

	/**
	 * Creates cafe pi notification
	 * 
	 * Creates the type of Cafe pi notification
	 * 
	 * Creates resource statement between this notification and related members
	 * 
	 * Creates resource statement between this notification and location where
	 * this events will occur
	 */
	public void createCafePiNotification() {

		// Seagent Notification is type of "Notification"
		instanceCreator.createInstance(
				HobNobInstanceVocabulary.NOTIFICATION_CAFE_PI_URI,
				HobNobVocabulary.NOTIFICATION_URI);

		// Creates Notification message about Seagent Notification
		instanceCreator.createLiteralStatement(
				HobNobInstanceVocabulary.NOTIFICATION_CAFE_PI_URI,
				HobNobVocabulary.NOTIFICATION_MESSAGE_URI,
				MSG_CAFEPI_NOTIFICATION);

		// Creates the resource statement of notification-member
		instanceCreator.createResourceStatement(
				HobNobInstanceVocabulary.NOTIFICATION_CAFE_PI_URI,
				HobNobVocabulary.NOTIFICATION_HAS_MEMBER_URI,
				HobNobInstanceVocabulary.MEMBER_BAHTI_URI,
				HobNobInstanceVocabulary.MEMBER_CEREN_URI);

		// Creates the resource statement of notification-location
		instanceCreator.createResourceStatement(
				HobNobInstanceVocabulary.NOTIFICATION_CAFE_PI_URI,
				HobNobVocabulary.NOTIFICATION_AT_LOCATION_URI,
				HobNobInstanceVocabulary.LOCATION_CAFE_PI_URI);
	}

	/**
	 * Creates location statements which related with cafe pi notification...
	 */
	public void createCafePiLocation() {
		// SeagentLocation is type of "Location"
		instanceCreator.createInstance(
				HobNobInstanceVocabulary.LOCATION_CAFE_PI_URI,
				HobNobVocabulary.LOCATION_URI);
		// x-Coordinate of SeagentLocation
		instanceCreator.createLiteralStatement(
				HobNobInstanceVocabulary.LOCATION_CAFE_PI_URI,
				HobNobVocabulary.X_COORDINATE, CAFE_PI_X_COORDINATE);
		// y-Coordinate of SeagentLocation
		instanceCreator.createLiteralStatement(
				HobNobInstanceVocabulary.LOCATION_CAFE_PI_URI,
				HobNobVocabulary.Y_COORDINATE, CAFE_PI_Y_COORDINATE);
		// City of where Seagent is located
		instanceCreator.createResourceStatement(
				HobNobInstanceVocabulary.LOCATION_CAFE_PI_URI,
				HobNobVocabulary.LOCATION_HAS_DBPEDIA_URI,
				HobNobInstanceVocabulary.IZMIR_URI);
	}

	/**
	 * Creates location statements which related with seagent notification...
	 */
	public void createSeagentLocation() {
		// SeagentLocation is type of "Location"
		instanceCreator.createInstance(
				HobNobInstanceVocabulary.LOCATION_SEAGENT_URI,
				HobNobVocabulary.LOCATION_URI);
		// x-Coordinate of SeagentLocation
		instanceCreator.createLiteralStatement(
				HobNobInstanceVocabulary.LOCATION_SEAGENT_URI,
				HobNobVocabulary.X_COORDINATE, SEAGENT_X_COORDINATE);
		// y-Coordinate of SeagentLocation
		instanceCreator.createLiteralStatement(
				HobNobInstanceVocabulary.LOCATION_SEAGENT_URI,
				HobNobVocabulary.Y_COORDINATE, SEAGENT_Y_COORDINATE);
		// City of where Seagent is located
		instanceCreator.createResourceStatement(
				HobNobInstanceVocabulary.LOCATION_SEAGENT_URI,
				HobNobVocabulary.LOCATION_HAS_DBPEDIA_URI,
				HobNobInstanceVocabulary.IZMIR_URI);
	}

	/**
	 * Creates statements that which related with seagent notification.
	 * 
	 * @return instanceModel
	 */
	public Model createSeagentModel() {
		// Seagent-notification is being created
		createSeagentNotification();
		// Seagent-location is being created
		createSeagentLocation();

		return instanceModel;

	}

	/**
	 * Creates seagent notification
	 * 
	 * Creates the type of Seagent notification
	 * 
	 * Creates resource statement between this notification and related members
	 * 
	 * Creates resource statement between this notification and location where
	 * this events will occur
	 */
	public void createSeagentNotification() {

		// Seagent Notification is type of "Notification"
		instanceCreator.createInstance(
				HobNobInstanceVocabulary.NOTIFICATION_SEAGENT_URI,
				HobNobVocabulary.NOTIFICATION_URI);

		// Creates Notification message about Seagent Notification
		instanceCreator.createLiteralStatement(
				HobNobInstanceVocabulary.NOTIFICATION_SEAGENT_URI,
				HobNobVocabulary.NOTIFICATION_MESSAGE_URI,
				MSG_SEAGENT_NOTIFICATION);

		// Creates the resource statement of notification-member
		instanceCreator.createResourceStatement(
				HobNobInstanceVocabulary.NOTIFICATION_SEAGENT_URI,
				HobNobVocabulary.NOTIFICATION_HAS_MEMBER_URI,
				HobNobInstanceVocabulary.MEMBER_BAHTI_URI,
				HobNobInstanceVocabulary.MEMBER_TAYFUN_URI);

		// Creates the resource statement of notification-location
		instanceCreator.createResourceStatement(
				HobNobInstanceVocabulary.NOTIFICATION_SEAGENT_URI,
				HobNobVocabulary.NOTIFICATION_AT_LOCATION_URI,
				HobNobInstanceVocabulary.LOCATION_SEAGENT_URI);
	}

	/**
	 * This function provide us to create istanbul notification statements.
	 */
	public void createInstanbulStatements() {
		HobNobTDBStore istanbul = new HobNobTDBStore();

		istanbul.istanbulNotificationStatements(instanceCreator);
		istanbul.istanbulLocationStatements(instanceCreator);
	}

}
